#coding:utf-8
'''
* coder  : dzlua
* email  : 505544956@qq.com
* module : ApiMgr-server
* path   : app/models
* file   : auth.py
* time   : 2017-11-09 11:21:59
'''
#--------------------#
from app.mgr import db
#--------------------#

#--------------------#
class Token(db.Model):
    __tablename__ = 'token'
    #----------#
    id = db.Column(db.Integer, primary_key = True)
    user_id = db.Column(db.Integer, unique=True, nullable=False, index=True)
    refresh_token = db.Column(db.String(512), unique=True, nullable=True)
    access_token = db.Column(db.String(512), unique=True, nullable=True)
    email_token = db.Column(db.String(512), unique=True, nullable=True)
    phone_token = db.Column(db.String(512), unique=True, nullable=True)
    #----------#
    @staticmethod
    def get(**kwargs):
        return Token.query.filter_by(**kwargs).first()
    @staticmethod
    def add(**kwargs):
        token = Token(**kwargs)
        db.session.add(token)
        db.session.commit()
    def update(self):
        db.session.commit()
#--------------------#
